package com.qfedu.mbti.controller;


import com.qfedu.mbti.config.SystemConfig;
import com.qfedu.mbti.param.UserAdd;
import com.qfedu.mbti.param.UserFind;
import com.qfedu.mbti.param.UserLogin;
import com.qfedu.mbti.param.UserLoginCode;
import com.qfedu.mbti.service.UserService;
import com.qfedu.mbti.vo.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 用户表(User)表控制层
 *
 * @author makejava
 * @since 2024-11-04 11:43:41
 */
@RestController
@RequestMapping("api/user")
@Tag(name = "用户模块")
@CrossOrigin
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService service;

    @Operation(summary = "注册")
    @PostMapping("register")
    public R register(@RequestBody UserAdd add){
        return service.register(add);
    }

    @Operation(summary = "登录")
    @PostMapping("login")
    public R login(@RequestBody UserLogin login){
        return service.login(login);
    }

    @Operation(summary = "修改密码")
    @PostMapping("updatepass")
    public R updatePass(@RequestBody Map<String,String> map, HttpServletRequest request){
        return service.updatePass(map.get("password"),request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @Operation(summary = "所有用户")
    @GetMapping("all")
    public R all(){
        return service.queryAll();
    }

    @Operation(summary = "发送登录验证码")
    @GetMapping("sendlcode")
    public R sendLcode(String phone){
        return service.sendLcode(phone);
    }

    @Operation(summary = "校验登录验证码")
    @PostMapping("logincode")
    public R loginCode(@RequestBody UserLoginCode code){
        return service.loginCode(code);
    }

    @Operation(summary = "密码找回验证码")
    @GetMapping("sendfcode")
    public R sendFcode(String phone){
        return service.sendFcode(phone);
    }

    @Operation(summary = "密码找回")
    @PostMapping("findpass")
    public R findPass(@RequestBody UserFind find){
        return service.findPass(find);
    }

}